package com.cayden.componets.canal;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * @author cayden
 * @date 2021-10-19 13:15
 */
@Slf4j
@Configuration
@EnableConfigurationProperties(CanalProperties.class)
public class CanalClientConfiguration {

    @Autowired
    private CanalProperties canalProperties;

    @Autowired
    @Qualifier("commonTaskExecutor")
    private ThreadPoolTaskExecutor commonTaskExecutor;

    @Bean
    @ConditionalOnProperty(name = "cayden.canal.client.enable", havingValue = "true")
    public SimpleCanalClient getCanalClient(CanalProperties canalProperties) {
        log.info("开始初始化canal实例");
        //创建组件实例
        SimpleCanalClient simpleCanalClientTest = new SimpleCanalClient(canalProperties);
        simpleCanalClientTest.setExecutor(commonTaskExecutor);
        simpleCanalClientTest.run();
        return simpleCanalClientTest;
    }

}
